/*
 
Copyright Eric C. McCreath 2012  <ericm@cs.anu.edu.au>

This file is part of the clapper-webcam-recorder project.

clapper-webcam-recorder is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.

clapper-webcam-recorder is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with clapper-webcam-recorder.  If not, see <http://www.gnu.org/licenses/>.

 */



#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

#include "util.h"
#include "x11display.h"

int mousexpos, mouseypos; 

struct x11displayinfo * setupx11display() {
  struct x11displayinfo *di;
   
    di = (struct x11displayinfo *) malloc(sizeof(struct x11displayinfo)); 
 
    di->display = XOpenDisplay(NULL);
    if (!di->display) s1_exit("problem connecting to display");
    di->rootwindow =  DefaultRootWindow(di->display);
       

    return di;

}

XImage * grabimage(struct x11displayinfo *di, int x, int y, int w, int h) {
int rx, ry, wx, wy;
unsigned int mr;
Window w1, w2;
XQueryPointer(di->display, di->rootwindow, &w1, &w2, &rx, &ry, &wx, &wy, &mr);
mousexpos = rx;
mouseypos = ry;
//printf("%d %d %d %d %d\n", rx, ry, wx, wy, mr);
      
     return XGetImage(di->display, di->rootwindow, x,y,w,h, AllPlanes, ZPixmap); // was XYPixmap
}





